home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / plotting.tex < prev    next >
Encoding:
Text File  |  1992-08-26  |  8.9 KB  |  370 lines

  1. %
  2. %    plotting.tex - TeX Plotting Macros
  3. %
  4. %    author: Laurence G. Yaffe (lgy@newton.phys.washington.edu)    1987
  5. %
  6. \setbox0 = \hbox{$0$}%
  7. \newdimen \digitheight        \digitheight  = \ht0
  8. \newdimen \titlespacing        \titlespacing = 1.5 ex
  9. \newdimen \labelspacing        \labelspacing = 0.9 ex
  10. \newdimen \labelwidth        \labelwidth   = 0.0 pt
  11. \newdimen \ticklength        \ticklength   = 0.7 em
  12. \newdimen \plotheight        \plotheight   = 5.0 in
  13. \newdimen \plotwidth        \plotwidth    = 5.0 in
  14. \newdimen \linewidth        \linewidth    = 0.241 pt
  15. \newskip  \padding        \padding      = 0pt plus 1fil
  16. %
  17. \newbox    \xAxis
  18. \newbox    \XAxis
  19. \newbox    \yAxis
  20. \newbox    \YAxis
  21. \newbox    \PlotData
  22. \newbox    \PlotBox
  23. %
  24. \def\ratio    #1:#2%        adjust padding for log scale plotting
  25.     {%
  26.     \count255 = #1#2
  27.     \ifnum \count255=11    \global\padding = 0pt plus 1.00000 fil \else
  28.     \ifnum \count255=12    \global\padding = 0pt plus 0.30103 fil \else
  29.     \ifnum \count255=23    \global\padding = 0pt plus 0.17609 fil \else
  30.     \ifnum \count255=34    \global\padding = 0pt plus 0.12494 fil \else
  31.     \ifnum \count255=45    \global\padding = 0pt plus 0.09691 fil \else
  32.     \ifnum \count255=56    \global\padding = 0pt plus 0.07918 fil \else
  33.     \ifnum \count255=67    \global\padding = 0pt plus 0.06695 fil \else
  34.     \ifnum \count255=78    \global\padding = 0pt plus 0.05799 fil \else
  35.     \ifnum \count255=89    \global\padding = 0pt plus 0.05115 fil \else
  36.     \ifnum \count255=91    \global\padding = 0pt plus 0.04576 fil \else
  37.     \ifnum \count255=13    \global\padding = 0pt plus 0.47712 fil \else
  38.     \ifnum \count255=14    \global\padding = 0pt plus 0.60206 fil \else
  39.     \ifnum \count255=24    \global\padding = 0pt plus 0.30103 fil \else
  40.     \ifnum \count255=25    \global\padding = 0pt plus 0.39794 fil \else
  41.     \ifnum \count255=26    \global\padding = 0pt plus 0.47712 fil \else
  42.     \ifnum \count255=36    \global\padding = 0pt plus 0.30103 fil \else
  43.     \ifnum \count255=46    \global\padding = 0pt plus 0.17609 fil \else
  44.     \ifnum \count255=61    \global\padding = 0pt plus 0.22185 fil \else
  45.     \ifnum \count255=51    \global\padding = 0pt plus 0.30103 fil \else
  46.     \ifnum \count255=41    \global\padding = 0pt plus 0.39794 fil \else
  47.     \ifnum \count255=31    \global\padding = 0pt plus 0.52288 fil \else
  48.     \ifnum \count255=21    \global\padding = 0pt plus 0.69897 fil \else
  49.             \global\padding = 0pt
  50.     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
  51.     }%
  52. %
  53. \def\centered    #1{\vbox to 0pt {\vss \hbox to 0pt {\hss #1\hss}\vss}}%
  54. %
  55. \def\dash    #1%
  56.     {%
  57.     \vbox {\hrule height 0.5 \linewidth depth 0.5 \linewidth width #1}%
  58.     }%
  59. %
  60. \def\yaxis    #1#2%
  61.     {%
  62.     \global\setbox \yAxis = \hbox
  63.     {%
  64.     \def \temp {#1}%
  65.     \ifx \temp\empty \else
  66.         \vbox to \plotheight {\vss \hbox {#1}\vss}%
  67.         \kern 0.7 \titlespacing
  68.     \fi
  69.     \def \temp {#2}%
  70.     \ifx \temp\empty \else
  71.         \labelwidth = 0pt
  72.         \setbox1=\box0\ytic #2,\cr,%
  73.         \ifnum \labelwidth = 0 \kern -\labelspacing \fi
  74.         \hbox to \labelwidth {\hfil}\box0%
  75.     \fi
  76.     \hbox to 0pt
  77.         {\hss \vrule height \plotheight depth 0pt width \linewidth \hss}%
  78.     }%
  79.     }%
  80. \def\ytic    #1,%
  81.     {%
  82.     \def \temp {#1}%
  83.     \def \quit {\cr}%
  84.     \ifx \temp\quit
  85.     \let\next=\relax
  86.     \setbox0 = \vbox to \plotheight {\unvbox0 \unskip}%
  87.     \else
  88.     \let\next=\ytic \skip0 = \padding
  89.     \setbox1 = \hbox {\tenpoint $#1$}%
  90.     \ifnum \labelwidth < \wd1
  91.            \labelwidth = \wd1
  92.     \fi
  93.     \setbox1 = \hbox
  94.         {%
  95.         \smash
  96.         {%
  97.         \ifnum \wd1 = 0
  98.             \kern \labelspacing
  99.             \hbox to 0pt {\dash {0.67 \ticklength}\hss}%
  100.         \else
  101.             \lower 0.42 \digitheight \hbox to 0pt {\hss \unhbox1}%
  102.             \kern \labelspacing
  103.             \hbox to 0pt {\dash \ticklength \hss}%
  104.         \fi
  105.         }%
  106.         }%
  107.     \setbox0 = \vbox to \plotheight {\box1 \vskip \skip0 \unvbox0}%
  108.     \fi
  109.     \next
  110.     }%
  111. %
  112. \def\Yaxis    #1#2%
  113.     {%
  114.     \global\setbox \YAxis = \hbox
  115.     {%
  116.     \hbox to 0pt
  117.         {\hss \vrule height \plotheight depth 0pt width \linewidth \hss}%
  118.     \def \temp {#2}%
  119.     \ifx \temp\empty \else \setbox1=\box0 \Ytic #2,\cr,\box0 \fi
  120.     \def \temp {#1}%
  121.     \ifx \temp\empty \else
  122.         \kern 0.7 \titlespacing
  123.         \vbox to \plotheight {\vss \hbox {#1}\vss}%
  124.     \fi
  125.     }%
  126.     }%
  127. \def\Ytic    #1,%
  128.     {%
  129.     \def \temp {#1}%
  130.     \def \quit {\cr}%
  131.     \ifx \temp\quit
  132.     \let\next=\relax
  133.     \setbox0 = \vbox to \plotheight {\unvbox0 \unskip}%
  134.     \else
  135.     \let\next=\Ytic \skip0=\padding
  136.     \setbox1 = \hbox {\tenpoint $#1$}%
  137.     \setbox1 = \hbox
  138.         {%
  139.         \smash
  140.         {%
  141.         \ifnum \wd1=0
  142.             \hbox to 0pt {\hss \dash {0.67 \ticklength}}%
  143.         \else
  144.             \hbox to 0pt {\hss \dash \ticklength}%
  145.             \kern \labelspacing
  146.             \lower 0.42 \digitheight \box1%
  147.         \fi
  148.         }%
  149.         }%
  150.     \setbox0 = \vbox to \plotheight {\box1 \vskip \skip0 \unvbox0}%
  151.     \fi
  152.     \next
  153.     }%
  154. %
  155. \def\xaxis    #1#2%
  156.     {%
  157.     \global\setbox \xAxis = \vtop
  158.     {%
  159.     \smash {\dash \plotwidth}%
  160.     \nointerlineskip
  161.     \def \temp {#2}%
  162.     \ifx \temp\empty \else \hbox to \plotwidth {\xtic #2,\cr,}\fi
  163.     \nointerlineskip
  164.     \def \temp {#1}%
  165.     \ifx \temp\empty \else
  166.         \kern 0.7 \titlespacing
  167.         \hbox to \plotwidth {\hss #1\hss}%
  168.     \fi
  169.     }%
  170.     }%
  171. \def\xtic    #1,%
  172.     {%
  173.     \def \temp {#1}%
  174.     \def \quit {\cr}%
  175.     \ifx \temp\quit
  176.     \let\next=\unskip
  177.     \else
  178.     \let\next=\xtic
  179.     \vtop
  180.         {%
  181.         \setbox1 = \hbox to 0pt {\hss \tenpoint $#1$\hss}%
  182.         \ifnum \ht1=0
  183.         \smash
  184.           {\hbox to 0pt
  185.             {\hss \vrule height 0.67 \ticklength width \linewidth \hss}%
  186.           }%
  187.         \else
  188.         \smash
  189.           {\hbox to 0pt
  190.             {\hss \vrule height \ticklength width \linewidth \hss}%
  191.           }%
  192.         \nointerlineskip
  193.         \kern \labelspacing
  194.         \box1%
  195.         \fi
  196.         }%
  197.     \hskip \padding
  198.     \fi
  199.     \next
  200.     }%
  201. %
  202. \def\Xaxis    #1#2%
  203.     {%
  204.     \global\setbox \XAxis = \vbox
  205.     {%
  206.     \def \temp {#1}%
  207.     \ifx \temp\empty \else
  208.         \hbox to \plotwidth {\hss #1\hss}%
  209.         \kern \titlespacing
  210.     \fi
  211.     \nointerlineskip
  212.     \def \temp {#2}%
  213.     \ifx \temp\empty \else \hbox to \plotwidth {\Xtic #2,\cr,}\fi
  214.     \nointerlineskip
  215.     \smash {\dash \plotwidth}%
  216.     }%
  217.     }%
  218. \def\Xtic    #1,%
  219.     {%
  220.     \def \temp {#1}%
  221.     \def \quit {\cr}%
  222.     \ifx \temp\quit
  223.     \let\next=\unskip
  224.     \else
  225.     \let\next=\Xtic
  226.     \vbox
  227.         {%
  228.         \setbox1 = \hbox to 0pt {\hss \tenpoint $#1$\hss}%
  229.         \ifnum \ht1=0
  230.         \smash
  231.           {\hbox to 0pt
  232.             {\hss \vrule depth 0.67 \ticklength width \linewidth \hss}%
  233.           }%
  234.         \else
  235.         \box1%
  236.         \kern \labelspacing
  237.         \nointerlineskip
  238.         \smash
  239.           {\hbox to 0pt
  240.             {\hss \vrule depth \ticklength width \linewidth \hss}%
  241.           }%
  242.         \fi
  243.         }%
  244.     \hskip \padding
  245.     \fi
  246.     \next
  247.     }%
  248. %
  249. \def\plotbox    (#1,#2)%
  250.     {%
  251.     \global\setbox \PlotData = \hbox to 0pt
  252.     {%
  253.     \unhbox \PlotData
  254.     \rlap {\kern #1\plotwidth \raise #2\plotheight \copy\PlotBox}%
  255.     }%
  256.     }%
  257. \def\plottext    (#1,#2)#3%
  258.     {%
  259.     \setbox \PlotBox = \hbox {#3}%
  260.     \plotbox (#1,#2)%
  261.     }%
  262. \def\plotpoint    (#1,#2)%
  263.     {%
  264.     \setbox \PlotBox = \centered.%
  265.     \plotbox (#1,#2)%
  266.     }%
  267. \def\plotsymbol    (#1,#2)#3%
  268.     {%
  269.     \setbox \PlotBox = \centered {#3}%
  270.     \plotbox (#1,#2)%
  271.     }%
  272. \def\xrange    #1]{\def\XRange {#1]}}%
  273. \def\yrange    #1]{\def\YRange {#1]}}%
  274. %
  275. \def\makeplot    #1#2#3%
  276.     {%
  277.     \plotwidth = #1 \plotheight = #2
  278.     \setbox \xAxis = \hbox to \plotwidth  {\hfil}%
  279.     \setbox \XAxis = \hbox to \plotwidth  {\hfil}%
  280.     \setbox \yAxis = \vbox to \plotheight {\vfil}%
  281.     \setbox \YAxis = \vbox to \plotheight {\vfil}%
  282.     \setbox \PlotData = \hbox {}%
  283.     {#3}%
  284.     \hbox
  285.     {%
  286.     \box \yAxis
  287.     \box \PlotData
  288.     \vbox
  289.         {%
  290.         \box \XAxis
  291.         \nointerlineskip \kern \plotheight \nointerlineskip
  292.         \box \xAxis
  293.         }%
  294.     \box \YAxis
  295.     }%
  296.     }%
  297. %
  298. \def\psfile    #1%        --- deferred input of postscript file ---
  299.     {%
  300.     \global\setbox \PlotData = \hbox to 0pt
  301.     {%
  302.     \unhbox \PlotData \special {psfile=#1}%
  303.     }%
  304.     }%
  305. %
  306. \def\addPS    #1%        --- immediate input of postscript commands ---
  307.     {%
  308.     \global\setbox \PlotData = \hbox to 0pt
  309.     {%
  310.     \unhbox \PlotData \special {"#1}%
  311.     }%
  312.     }%
  313. %
  314. \def\plotdatafile    #1#2%        --- deferred input of data file ---
  315.     {%
  316.     \global\setbox \PlotData = \hbox to 0pt
  317.     {%
  318.     \unhbox \PlotData
  319.     \special
  320.         {%
  321.         datafile="#1"
  322.         dash="[#2]"
  323.         xrange="\XRange"
  324.         yrange="\YRange"
  325.         hsize=\the\plotwidth\space
  326.         vsize=\the\plotheight\space
  327.         linewidth=\the\linewidth
  328.         }%
  329.     }%
  330.     }%
  331. %
  332. \def\plotdata    #1#2%            --- immediate input of data points ---
  333.     {%
  334.     \global\setbox \PlotData = \hbox to 0pt
  335.     {%
  336.     \unhbox \PlotData
  337.     \special
  338.         {%
  339.         datalist="#1"
  340.         dash="[#2]"
  341.         xrange="\XRange"
  342.         yrange="\YRange"
  343.         hsize=\the\plotwidth\space
  344.         vsize=\the\plotheight\space
  345.         linewidth=\the\linewidth
  346.         }%
  347.     }%
  348.     }%
  349. %
  350. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  351. %
  352. %    Trivial Plotting Example
  353. %
  354. %\makeplot {5 in}{4.5 in}%
  355. %    {%
  356. %    \linewidth = 0.3 pt
  357. %    \Xaxis {Title}{}
  358. %    \Yaxis {\kern -5pt $Y$}{,2,4,6,8,10}
  359. %    \yaxis {$y$}{0.0,,0.2,,0.4,,0.6,,0.8,,1.0}
  360. %    \xaxis {$x$}{10^0 \ratio 1:2,\ratio 2:3,\ratio 3:4,\ratio 4:5,\ratio 5:6,
  361. %              \ratio 6:7,\ratio 7:8,\ratio 8:9,\ratio 9:1,
  362. %         10^1 \ratio 1:2,\ratio 2:3,\ratio 3:4,\ratio 4:5,\ratio 5:6,
  363. %              \ratio 6:7,\ratio 7:8,\ratio 8:9,\ratio 9:1,
  364. %         10^2 \ratio 1:1}
  365. %    \plotsymbol (.9,.9)a
  366. %    \plottext  (.2,.4){some text}
  367. %    \plottext (.25,.7){more text}
  368. %    }%
  369. %\bye
  370.